package com.sxfq.loansupermarket.backsystem.modular.doctorLooked.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Dept;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.User;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.support.DateTime;
import com.sxfq.loansupermarket.backsystem.core.support.DateTimeKit;
import com.sxfq.loansupermarket.backsystem.core.util.AliyunOssUtil;
import com.sxfq.loansupermarket.backsystem.core.util.CommUtils;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.IntegralMall.entity.iconInfoStatus;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.CustomerInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.FirstCustomerInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.service.ICustomerDetailsService;
import com.sxfq.loansupermarket.backsystem.modular.arrival.service.ICustomerService;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.dao.DoctorLookedDao;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.entity.*;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.service.IDoctorLookedService;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.ReservationsInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.service.IReservationsService;
import com.sxfq.loansupermarket.backsystem.modular.websocket.WebSocket;
import com.sxfq.loansupermarket.backsystem.modular.weixin.config.MemberEnumConfig;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@Transactional
public class DoctorLookedServiceImpl implements IDoctorLookedService {
    @Autowired
    private DoctorLookedDao dao;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    IReservationsService reservationsService;

    @Autowired
    ICustomerDetailsService customerDetailsService;

    @Autowired
    ICustomerService customerService;

    @Autowired
    private SqlMapper sqlMapper;

    @Autowired
    AliyunOssUtil aliyunOssUtil;

    @Autowired
    WebSocket webSocket;

    @Override
    public List<DoctorLookedInfo> selectPageListByQueryGetMap(Page<DoctorLookedInfo> page, SearchDoctorLookedInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalTime())) {
            params.put("arrivalTime", searchInfo.getArrivalTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerSex())) {
            params.put("customerSex", searchInfo.getCustomerSex());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerAgeStart())) {
            params.put("customerAgeStart", searchInfo.getCustomerAgeStart());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerAgeEnd())) {
            params.put("customerAgeEnd", searchInfo.getCustomerAgeEnd());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }
        //String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableHead = searchInfo.getAbbreviation();
        params.put("tableName1", tableHead+"customer_info");
        params.put("tableName", tableHead+"deal_info");
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPage(page, params);
    }

    public int getQueryPagesCount(Page<DoctorLookedInfo> page, SearchDoctorLookedInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalTime())) {
            params.put("arrivalTime", searchInfo.getArrivalTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerSex())) {
            params.put("customerSex", searchInfo.getCustomerSex());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerAgeStart())) {
            params.put("customerAgeStart", searchInfo.getCustomerAgeStart());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerAgeEnd())) {
            params.put("customerAgeEnd", searchInfo.getCustomerAgeEnd());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }
        String tableHead = searchInfo.getAbbreviation();
        params.put("tableName1", tableHead+"customer_info");
        params.put("tableName", tableHead+"deal_info");
        return dao.getQueryPagesCount(page, params);
    }

    @Override
    public List<DoctorOperationInfo> selectDoctorGetMap(Page<DoctorOperationInfo> page, SearchDoctorOperationInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getOperationTime())) {
            params.put("operationTime", searchInfo.getOperationTime());
        }
        if ("1".equals(searchInfo.getUserName())) {
            params.put("operationPeople", "");
        } else {
            params.put("operationPeople", searchInfo.getUserName());
        }
        String tableHead = searchInfo.getAbbreviation();
        params.put("tableName1", tableHead+"customer_info");
        params.put("store", searchInfo.getOutpatientName());
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryDoctorPages(page, params);
    }

    // 智能评分
    @Override
    public List<CaseSelectionIntelligentScoreInfo> getIntelligentScoreDetailsList(Page<CaseSelectionIntelligentScoreInfo> page, SearchCaseSelectionIntelligentScoreInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getNum())) {
            params.put("num", searchInfo.getNum());
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.CaseSelectionIntelligentScoreList2(page, params);
    }

    //智能评分
    @Override
    public int getIntelligentScoreDetailsCount(Page<CaseSelectionIntelligentScoreInfo> page, SearchCaseSelectionIntelligentScoreInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getId2())) {
            params.put("id2", searchInfo.getId2());
        }
        return dao.getIntelligentScoreDetailsCount(page, params);

    }

    @Override
    public int getQueryPagesDoctorCount(Page<DoctorOperationInfo> page, SearchDoctorOperationInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getOperationTime())) {
            params.put("operationTime", searchInfo.getOperationTime());
        }
        if ("1".equals(searchInfo.getUserName())) {
            params.put("operationPeople", "");
        } else {
            params.put("operationPeople", searchInfo.getUserName());
        }
        String tableHead = searchInfo.getAbbreviation();
        params.put("tableName1", tableHead+"customer_info");
        params.put("store", searchInfo.getOutpatientName());
        return dao.getQueryPagesDoctorCount(page, params);
    }

    @Override
    public int getQueryPagesRevisitCount(Page<DoctorLookedInfo> page, SearchDoctorLookedInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisitStatus())) {
            params.put("revisitStatus", searchInfo.getRevisitStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartRevisitTime())) {
            params.put("startRevisitTime", searchInfo.getStartRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndRevisitTime())) {
            params.put("endRevisitTime", searchInfo.getEndRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisit())) {
            params.put("revisit", searchInfo.getRevisit());
        }
        String tableHead = searchInfo.getAbbreviation();
        params.put("tableName", tableHead+"customer_info");
        params.put("outpatientName", searchInfo.getOutpatientName());
        return dao.getQueryPagesRevisitCount(page, params);
    }

    @Override
    public int getQueryPagesPerformanceCount(Page<DoctorChangePriceInfo> page, SearchDoctorChangePriceInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getTreatmentUnit())) {
            params.put("treatmentUnit", searchInfo.getTreatmentUnit());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFieldTc())) {
            params.put("fieldTc", searchInfo.getFieldTc());
        }
        if (StringUtil.isNotEmpty(searchInfo.getAppointmentPayService())) {
            params.put("appointmentPayService", searchInfo.getAppointmentPayService());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        } else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableName1 = tableHead + "triage_performance";
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("tableName1", tableName1);
        return dao.getQueryPagesPerformanceCount(page, params);
    }

    @Override
    public int getQueryPagesCountFen(Page<DoctorChangePriceInfo> page, SearchDoctorChangePriceInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getTreatmentUnit())) {
            params.put("treatmentUnit", searchInfo.getTreatmentUnit());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFieldTc())) {
            params.put("fieldTc", searchInfo.getFieldTc());
        }
        if (StringUtil.isNotEmpty(searchInfo.getAppointmentPayService())) {
            params.put("appointmentPayService", searchInfo.getAppointmentPayService());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        } else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableName1 = tableHead + "triage_performance";
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("tableName1", tableName1);
        return dao.getQueryPagesCountFen(page, params);
    }

    @Override
    public List<DoctorLookedInfo> selectChargeSchedule(Page<DoctorLookedInfo> page, SearchDoctorLookedInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getPayServiceName())) {
            params.put("payServiceName", searchInfo.getPayServiceName());
        }
        String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
        User user = sqlMapper.selectOne(sql, User.class);
        if (user != null) {
            if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                if (StringUtil.isNotEmpty(searchInfo.getReach())) {
                    params.put("doctor", searchInfo.getReach());
                } else {
                    params.put("doctor", "");
                }
            } else {
                params.put("doctor", ShiroKit.getUser().getAccount());
            }
        }
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableName1 = tableHead + "deal_info";
        params.put("tableName1", tableName1);
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("pay_service_info", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"pay_service_info",0));
        return dao.getQueryPageChargeSchedule(page, params);
    }

    //医生划价预览
    public List<DoctorLookedInfo> selectDoctorChargePrice(Page<DoctorLookedInfo> page, SearchDoctorLookedInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCheckStatus())) {
            params.put("checkStatus", searchInfo.getCheckStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getExecuteStatus())) {
            params.put("executeStatus", searchInfo.getExecuteStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableName1 = tableHead + "deal_info";
        params.put("tableName1", tableName1);
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        return dao.getQueryPageDoctorChargePrice(page, params);
    }

    @Override
    public List<DoctorLookedInfo> chargeScheduleExportt(SearchDoctorLookedInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getPayServiceName())) {
            params.put("payServiceName", searchInfo.getPayServiceName());
        }
        String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
        User user = sqlMapper.selectOne(sql, User.class);
        if (user != null) {
            if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                params.put("doctor", "");
            } else {
                params.put("doctor", ShiroKit.getUser().getAccount());
            }
        }
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableName1 = tableHead + "deal_info";
        params.put("tableName1", tableName1);
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("pay_service_info", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"pay_service_info",0));
        return dao.getQueryPageChargeScheduleExportt(params);
    }

    @Override
    public List<DoctorLookedInfo> doctorChargePriceExport(SearchDoctorLookedInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCheckStatus())) {
            params.put("checkStatus", searchInfo.getCheckStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableName1 = tableHead + "deal_info";
        params.put("tableName1", tableName1);
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("pay_service_info", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"pay_service_info",0));
        return dao.getQueryPageDoctorChargePriceExport(params);
    }

    //医生业绩 导出
    @Override
    public List<DoctorChangePriceInfo> customerExport(SearchDoctorChangePriceInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerName())) {
            params.put("customerName", searchInfo.getCustomerName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerPhone())) {
            params.put("customerPhone", searchInfo.getCustomerPhone());
        }

        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getTreatmentUnit())) {
            params.put("treatmentUnit", searchInfo.getTreatmentUnit());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDimensionSelection())) {
            params.put("dimensionSelection", searchInfo.getDimensionSelection());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFieldTc())) {
            params.put("fieldTc", searchInfo.getFieldTc());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        } else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }

        if (StringUtil.isNotEmpty(searchInfo.getAppointmentPayService())) {
            String appointmentPayService = "";
            String appointmentPayServices[] = searchInfo.getAppointmentPayService().split(",");
            if (appointmentPayServices.length == 1) {
                appointmentPayService = appointmentPayServices[0];
            } else {
                for (int i = 0; i < appointmentPayServices.length; i++) {
                    if (i == (appointmentPayServices.length - 1)) {
                        appointmentPayService += "'" + appointmentPayServices[i];
                    } else if (i == 0) {
                        appointmentPayService += appointmentPayServices[i] + "'" + ",";
                    } else {
                        appointmentPayService += "'" + appointmentPayServices[i] + "'" + ",";
                    }
                }
            }
            params.put("appointmentPayService", " t1.appointment_pay_service in ('" + appointmentPayService + "')");
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            String arrivalStore = "";
            String arrivalStores[] = searchInfo.getArrivalStore().split(",");
            if (arrivalStores.length == 1) {
                arrivalStore = arrivalStores[0];
            } else {
                for (int i = 0; i < arrivalStores.length; i++) {
                    if (i == (arrivalStores.length - 1)) {
                        arrivalStore += "'" + arrivalStores[i];
                    } else if (i == 0) {
                        arrivalStore += arrivalStores[i] + "'" + ",";
                    } else {
                        arrivalStore += "'" + arrivalStores[i] + "'" + ",";
                    }
                }
            }
            params.put("arrivalStore", " t1.arrival_store in ('" + arrivalStore + "')");
        }
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableName1 = tableHead + "deal_info";
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("tableName1", tableName1);
        return dao.getQueryDoctorPage(params);
    }

    @Transactional
    public void deleteOperationRecords(String id) {
        String deletesql = "delete from today_operation_info where id=" + id + "";
        sqlMapper.delete(deletesql);
    }

    /**
     * 医生随访
     *
     * @param page
     * @param searchInfo
     * @return
     */
    public List<DoctorLookedInfo> selectPageListByDoctorRevisit(Page<DoctorLookedInfo> page, SearchDoctorLookedInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisitStatus())) {
            params.put("revisitStatus", searchInfo.getRevisitStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartRevisitTime())) {
            params.put("startRevisitTime", searchInfo.getStartRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndRevisitTime())) {
            params.put("endRevisitTime", searchInfo.getEndRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("userName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisit())) {
            params.put("revisit", searchInfo.getRevisit());
        }
        String tableHead = searchInfo.getAbbreviation();
        params.put("tableName", tableHead+"customer_info");
        params.put("outpatientName", searchInfo.getOutpatientName());
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPages(page, params);
    }

    public DoctorLookedInfo selectOneById(String id) {
        String sql = "select " +
                "  (CASE a.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,a.* from reservations_info a where id= '" + id + "' limit 0,1";
        DoctorLookedInfo info = sqlMapper.selectOne(sql, DoctorLookedInfo.class);
        return info;
    }

    public List<SfInfo> getSfList() {
        String sql = "select * from follow_template where user='" + ShiroKit.getUser().getAccount() + "'";
        List<SfInfo> list = sqlMapper.selectList(sql, SfInfo.class);
        return list;
    }

    public List<SfInfo> getJzList() {
        String sql = "select * from orthodontic_template where user='" + ShiroKit.getUser().getAccount() + "'";
        List<SfInfo> list = sqlMapper.selectList(sql, SfInfo.class);
        return list;
    }

    public List<SfInfo> getSjList() {
        String sql = "select * from design_scheme where user='" + ShiroKit.getUser().getAccount() + "'";
        List<SfInfo> list = sqlMapper.selectList(sql, SfInfo.class);
        return list;
    }

    public List<JgInfo> getJgList() {
        String sql = "select * from follow_results_template where user='" + ShiroKit.getUser().getAccount() + "'";
        List<JgInfo> list = sqlMapper.selectList(sql, JgInfo.class);
        return list;
    }

    public SfInfo getSfById(String id) {
        String sql = "select * from follow_template where id='" + id + "'";
        SfInfo info = sqlMapper.selectOne(sql, SfInfo.class);
        return info;
    }

    public SfInfo getJzById(String id) {
        String sql = "select * from orthodontic_template where id='" + id + "'";
        SfInfo info = sqlMapper.selectOne(sql, SfInfo.class);
        return info;
    }

    public SfInfo getSjById(String id) {
        String sql = "select * from design_scheme where id='" + id + "'";
        SfInfo info = sqlMapper.selectOne(sql, SfInfo.class);
        return info;
    }

    public SfInfo getJgById(String id) {
        String sql = "select * from follow_results_template where id='" + id + "'";
        SfInfo info = sqlMapper.selectOne(sql, SfInfo.class);
        return info;
    }

    //患者第二次到店，判断是今天到店的还是以前来过，今天到店多次客户状态都是新客首次，
    public String getNewCustomerStatus(String reservationsId) {
        String sql = "select id from distinction_customer_status where " +
                " reservations_id='" + reservationsId + "' and left(add_time,10)<left(now(),10) and status=1 ; ";
        List<CustomerInfo> list = sqlMapper.selectList(sql, CustomerInfo.class);
        if (list.size() > 0) {
            return getOldOrReconsultingStatus(reservationsId);
        } else {
            return "新客首次";
        }
    }

    //点重咨，判断之前来店是否有成交，有为老客，从来没有为新客多次
    public String getOldOrReconsultingStatus(String reservationsId) {
        String sql = "select id from distinction_customer_status where " +
                " reservations_id='" + reservationsId + "' and deal_status='已成交' and left(update_time,10)<left(now(),10) and status=1 ; ";
        List<CustomerInfo> list = sqlMapper.selectList(sql, CustomerInfo.class);
        if (list.size() > 0) {
            return "老客";
        } else {
            String sql1 = "select id from "+redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) +" where " +
                    " reservations_id='" + reservationsId + "' and customer_status='新客多次' and left(arrival_time,10)<left(now(),10) ";
            List<CustomerInfo> list1 = sqlMapper.selectList(sql1, CustomerInfo.class);
            if(list1.size()>0){
                return "新客N次";
            }else{
                return "新客多次";
            }
        }
    }

    @Override
    public int regresses(String customerId) {
        String selectiscom = "select id from " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " " +
                "where id='" + customerId + "' and left(start_time,10)>left(now(),10)";
        List<CustomerInfo> iscomList = sqlMapper.selectList(selectiscom, CustomerInfo.class);
        if (iscomList.size() > 0) {
            return 1;
        } else {
            String selsql = "select id,a.arrival_status,(case a.arrival_status when (1 or 9) then '预约' when 2 then '到店' when 3 then '就诊中' " +
                    "when 4 then '完成治疗' when 5 then '离开' when (6 or 10) then '已打电话' " +
                    "when 7 then '失约' when 8 then '取消预约' else '其他' end) as arrivalStatusName," +
                    "a.* from  " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " a where id = '" + customerId + "'";
            CustomerInfo customerInfo = sqlMapper.selectOne(selsql, CustomerInfo.class);
            String customerStatus = this.getNewCustomerStatus(customerInfo.getReservationsId());
            String sql = "";
            String selectsql1 = "select id,status,follower,archiving,belonger,szm,first_visit_date from reservations_info a where a.id='" + customerInfo.getReservationsId() + "' limit 0,1";
            ReservationsInfo reservationsInfo = sqlMapper.selectOne(selectsql1, ReservationsInfo.class);
            String medicalRecordNumber = "";
            String scarchiving = "";
            if (reservationsInfo != null) {
                if (StringUtil.isNotEmpty(reservationsInfo.getFollower())) {
                    scarchiving = reservationsInfo.getFollower();
                } else {
                    scarchiving = reservationsInfo.getArchiving();
                }
                if ("预约".equals(reservationsInfo.getStatus())) {
                    medicalRecordNumber = customerService.getMedicalRecordNumbers(customerInfo.getCustomerPhone(), redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"medicalrecord_info",0)+"");
                    String sql1 = "update reservations_info a set a.status='到店', a.arrival_store='" + ShiroKit.getUser().getOutpatientName() + "'," +
                            "a.belonger='" + scarchiving + "', a.identification_number='" + medicalRecordNumber + "',a.first_visit_date='" + DateTimeKit.now() + "'" +
                            " where id='" + customerInfo.getReservationsId() + "'";
                    sqlMapper.update(sql1);
                    String sql2 = "update reservations_infosc a set a.status='到店', a.arrival_store='" + ShiroKit.getUser().getOutpatientName() + "'," +
                            "a.belonger='" + scarchiving + "', a.identification_number='" + medicalRecordNumber + "',a.first_visit_date='" + DateTimeKit.now() + "'" +
                            " where id='" + customerInfo.getReservationsId() + "'";
                    sqlMapper.update(sql2);
                }
            } else {
                medicalRecordNumber = customerService.getMedicalRecordNumbers(customerInfo.getCustomerPhone(), redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"medicalrecord_info",0)+"");
                customerInfo.setIdentificationNumber(medicalRecordNumber);
                reservationsService.insert(customerInfo);
            }
            String selectsql2 = "select * from distinction_customer_status " +
                    " where reservations_id='" + customerInfo.getReservationsId() + "' " +
                    "and arrival_store='" + ShiroKit.getUser().getOutpatientName() + "' and status=1 ";
            List<CustomerInfo> cInfo2 = sqlMapper.selectList(selectsql2, CustomerInfo.class);
            if (cInfo2.size() == 0) {  //第一次来本店
                String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
                String tableName = tableHead + "customer_info";
                String sqld = "select id,abbreviation from distinction_customer_status " +
                        " where reservations_id ='" + customerInfo.getReservationsId() + "' and status=1 order by add_time desc limit 0,1 ";
                Dept infod = sqlMapper.selectOne(sqld, Dept.class);
                if (infod != null) {   //没来过本店，去过另一家店
                    tableName = infod.getAbbreviation() + "customer_info";
                    String sqld1 = "select id as id,medical_record_number as medicalRecordNumber from " + tableName + " where reservations_id ='" + customerInfo.getReservationsId() + "' order by arrival_time desc limit 0,1 ";
                    CustomerInfo infod1 = sqlMapper.selectOne(sqld1, CustomerInfo.class);
                    medicalRecordNumber = infod1.getMedicalRecordNumber();
                } else if ("".equals(medicalRecordNumber)) {
                    medicalRecordNumber = customerService.getMedicalRecordNumbers(customerInfo.getCustomerPhone(), redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"medicalrecord_info",0)+"");
                }
                String sqld2 = "delete from distinction_customer_status " +
                        " where reservations_id='" + customerInfo.getReservationsId() + "' " +
                        "and arrival_store='" + ShiroKit.getUser().getOutpatientName() + "' and status=2 ";
                sqlMapper.delete(sqld2);
                String sql1 = "insert into distinction_customer_status (reservations_id,customer_name,customer_phone,arrival_store,abbreviation,deal_status,add_time,update_time,medical_record_number) " +
                        " values('" + customerInfo.getReservationsId() + "','" + customerInfo.getCustomerName() + "','" + customerInfo.getCustomerPhone()
                        + "','" + ShiroKit.getUser().getOutpatientName() + "','" + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"" + "','未成交','"
                        + DateTimeKit.now() + "','" + DateTimeKit.now() + "','" + medicalRecordNumber + "') ";
                sqlMapper.insert(sql1);
                sql = "update " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + "  set arrival_status ='2',medical_record_number='" + medicalRecordNumber + "'," +
                        "scarchiving='" + scarchiving + "',status='到店',szm=firstconcats('" + customerInfo.getCustomerName() + "') ,customer_status='" + customerStatus + "'," +
                        "arrival_time='" + DateTimeKit.now() + "',first_visit_date='" + DateTimeKit.now() + "' where id = '" + customerId + "' ";
            } else {  //复诊
                if ("新客首次".equals(customerStatus)) {
                    customerStatus = "新客首次";
                } else if ("新客多次".equals(customerStatus)) {
                    customerStatus = "新客多次";
                } else if ("新客N次".equals(customerStatus)) {
                    customerStatus = "新客N次";
                } else {
                    customerStatus = "复诊";
                }
                String sqlgetm = "select id,medical_record_number,phone_shar_ship from " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " " +
                        " where customer_phone='" + customerInfo.getCustomerPhone() + "' and reservations_id='" + customerInfo.getReservationsId() + "'" +
                        " and left(arrival_time,10)<'" + DateTimeKit.now().substring(0, 10) + "' limit 0,1";
                CustomerInfo customerInfo2 = sqlMapper.selectOne(sqlgetm, CustomerInfo.class);
                if (customerInfo2 != null) {
                    sql = "update " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + "  set arrival_status ='2',status='到店',phone_shar_ship='" + customerInfo2.getPhoneSharShip() + "'," +
                            "medical_record_number='" + customerInfo2.getMedicalRecordNumber() + "',status='到店',customer_status='" + customerStatus + "'," +
                            "arrival_time='" + DateTimeKit.now() + "' where id = '" + customerId + "' ";
                } else {
                    String sqlgetm2 = "select id,medical_record_number,phone_shar_ship from " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " " +
                            " where customer_name='" + customerInfo.getCustomerName() + "' and reservations_id='" + customerInfo.getReservationsId() + "' limit 0,1";
                    CustomerInfo customerInfo22 = sqlMapper.selectOne(sqlgetm2, CustomerInfo.class);
                    sql = "update " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + "  set arrival_status ='2',status='到店',phone_shar_ship='" + customerInfo22.getPhoneSharShip() + "'," +
                            "scarchiving='" + scarchiving + "',medical_record_number='" + customerInfo22.getMedicalRecordNumber() + "',status='到店',customer_status='" + customerStatus + "'," +
                            "arrival_time='" + DateTimeKit.now() + "' where id = '" + customerId + "' ";
                }
            }
            //根据预约ID 查询最近一次到店时间的患者
            CustomerInfo info = customerDetailsService.firstVisitInformations(customerInfo.getReservationsId()); //首次到店的患者信息
            if (info != null) {
                if (info.getReferralerPerson() == null || info.getReferralerPerson() == "" || info.getReferralerPersoned() == null || info.getReferralerPersoned() == "" || info.getReferralerTime() == null || info.getReferralerTime() == "" || info.getReferralerRemarks() == null || info.getReferralerRemarks() == "") {
                    info.setReferralerPerson("null");
                    info.setReferralerPersoned("null");
                    info.setReferralerRemarks("null");
                    info.setReferralerTime(null);
                } else {
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                    Date dt1 = null;
                    Date dt2 = null;
                    try {
                        dt1 = df.parse(DateTimeKit.now().substring(0, 10));
                        dt2 = df.parse(info.getReferralerTime().substring(0, 10));
                        if (dt1.getTime() - dt2.getTime() > 30 * 24 * 60 * 60 * 1000L) {
                            info.setReferralerPerson("null");
                            info.setReferralerPersoned("null");
                            info.setReferralerRemarks("null");
                            info.setReferralerTime(null);
                        } else {
                            info.setReferralerPerson(info.getReferralerPerson());
                            info.setReferralerPersoned(info.getReferralerPersoned());
                            info.setReferralerTime(info.getReferralerTime());
                            info.setReferralerRemarks(info.getReferralerRemarks());
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                String referralerPerson = "";
                String referralerPersoned = "";
                String referralerTime = "";
                String referralerRemarks = "";
                String marketFilingTime = "";
                if (StringUtil.isNotEmpty(reservationsInfo.getFirstVisitDate())) {
                    marketFilingTime = "'" + reservationsInfo.getFirstVisitDate() + "'";
                } else {
                    marketFilingTime = null;
                }
                if (StringUtil.isNotEmpty(info.getReferralerPerson())) {
                    referralerPerson = "'" + info.getReferralerPerson() + "'";
                } else {
                    referralerPerson = "null";
                }
                if (StringUtil.isNotEmpty(info.getReferralerPersoned())) {
                    referralerPersoned = "'" + info.getReferralerPersoned() + "'";
                } else {
                    referralerPersoned = "null";
                }
                if (StringUtil.isNotEmpty(info.getReferralerTime())) {
                    referralerTime = "'" + info.getReferralerTime() + "'";
                } else {
                    referralerTime = null;
                }
                if (StringUtil.isNotEmpty(info.getReferralerRemarks())) {
                    referralerRemarks = "'" + info.getReferralerRemarks() + "'";
                } else {
                    referralerRemarks = "null";
                }
                String updateSql = "update " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " a set a.referraler_person=" + referralerPerson + ",a.referraler_personed=" + referralerPersoned + "," +
                        " a.referraler_time=" + referralerTime + ",a.referraler_remarks=" + referralerRemarks + ",a.market_filing_time="+marketFilingTime+" where id='" + customerId + "' ";
                sqlMapper.update(updateSql);
            }
            //插入视图改动日志 点击挂号
            String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                    " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                    " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','挂号', '"
                    + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                    "','预约状态：" + customerInfo.getArrivalStatusName() + "->挂号','" + customerId + "','" + customerInfo.getReservationsId() + "');";
            sqlMapper.insert(sq11);
            sqlMapper.update(sql);
            webSocket.sendMessageViews("挂号", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"");
            return 0;
        }
    }

    /**
     * 插入病历数据
     *
     * @param info
     * @return
     */
    @Override
    public String insert(CaseInfo info) {
        String id = CommUtils.getUUID();
        Random rand = new Random();
        int randomNumber = rand.nextInt(999999);
        id = id + randomNumber;
        String finnallyTime = "";
        if (info.getFinnallyTime() == null || info.getFinnallyTime() == "") {
            finnallyTime = "null";
        } else {
            finnallyTime = "'" + info.getFinnallyTime() + "'";
        }
        String sql11="select * from dept where simplename='"+ ShiroKit.getUser().getOutpatientName()+"'";
        Dept dept=sqlMapper.selectOne(sql11,Dept.class);
        String sql22="select * from "+dept.getAreaAbbreviation()+"pay_service_info where id='"+info.getPayServiceId()+"'";
        PayServiceInfo py=sqlMapper.selectOne(sql22,PayServiceInfo.class);
        String sql = "insert into case_info (`id`,`customer_id`,`reservations_id`,`zhushu`,`doctor_id`,`nurse_id`,`type`,`now_medical_history`,`before_medical_history`,`finnally_time`,`doctor_advice`,`lable`,remarkss" +
                ",mouth_check ,auxiliary_check ,diagnose ,remedy_plan ,dispose ,pay_service_id,status,arrival_store,abbreviation,founder,update_time) VALUES" +
                "('" + id + "','" + info.getCustomerId() + "','" + info.getReservationsId() + "','" + info.getZhushu() + "','" + info.getDoctorId() + "','" + info.getNurseId() + "','" + info.getType() + "','" + info.getNowMedicalHistory() + "','" + info.getBeforeMedicalHistory() + "'" +
                "," + finnallyTime + ",'" + info.getDoctorAdvice() + "' ,'" + info.getLable() + "','" + info.getRemarks() + "','1','2','3','4','5'" +
                ",'" + info.getPayServiceId() + "'," + info.getStatus() + ",'" + ShiroKit.getUser().getOutpatientName()
                + "','" + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"" + "','" + ShiroKit.getUser().getAccount()
                + "','" + DateTimeKit.now() + "');";
        sqlMapper.insert(sql);
        String case_id = id;
        //第一组检查循环插入
        String[] leftUp1 = info.getLeftUp1().split("&&", -1);
        String[] rightUp1 = info.getRightUp1().split("&&", -1);
        String[] leftDown1 = info.getLeftDown1().split("&&", -1);
        String[] rightDown1 = info.getRightDown1().split("&&", -1);
        String[] remarks1 = info.getRemarks1().split("&&", -1);
        for (int i = 0; i < leftUp1.length; i++) {
            String sql1 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','1','" + leftUp1[i] + "','" + rightUp1[i] + "','" + leftDown1[i] + "','" + rightDown1[i] + "','" + remarks1[i] + "')";
            sqlMapper.insert(sql1);
        }
        //第二组检查循环插入
        String[] leftUp2 = info.getLeftUp2().split("&&", -1);
        String[] rightUp2 = info.getRightUp2().split("&&", -1);
        String[] leftDown2 = info.getLeftDown2().split("&&", -1);
        String[] rightDown2 = info.getRightDown2().split("&&", -1);
        String[] remarks2 = info.getRemarks2().split("&&", -1);
        for (int i = 0; i < leftUp2.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','2','" + leftUp2[i] + "','" + rightUp2[i] + "','" + leftDown2[i] + "','" + rightDown2[i] + "','" + remarks2[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第三组检查循环插入
        String[] leftUp3 = info.getLeftUp3().split("&&", -1);
        String[] rightUp3 = info.getRightUp3().split("&&", -1);
        String[] leftDown3 = info.getLeftDown3().split("&&", -1);
        String[] rightDown3 = info.getRightDown3().split("&&", -1);
        String[] remarks3 = info.getRemarks3().split("&&", -1);
        for (int i = 0; i < leftUp3.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','3','" + leftUp3[i] + "','" + rightUp3[i] + "','" + leftDown3[i] + "','" + rightDown3[i] + "','" + remarks3[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第四组检查循环插入
        String[] leftUp4 = info.getLeftUp4().split("&&", -1);
        String[] rightUp4 = info.getRightUp4().split("&&", -1);
        String[] leftDown4 = info.getLeftDown4().split("&&", -1);
        String[] rightDown4 = info.getRightDown4().split("&&", -1);
        String[] remarks4 = info.getRemarks4().split("&&", -1);
        for (int i = 0; i < leftUp4.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','4','" + leftUp4[i] + "','" + rightUp4[i] + "','" + leftDown4[i] + "','" + rightDown4[i] + "','" + remarks4[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第五组检查循环插入
        String[] leftUp5 = info.getLeftUp5().split("&&", -1);
        String[] rightUp5 = info.getRightUp5().split("&&", -1);
        String[] leftDown5 = info.getLeftDown5().split("&&", -1);
        String[] rightDown5 = info.getRightDown5().split("&&", -1);
        String[] remarks5 = info.getRemarks5().split("&&", -1);
        for (int i = 0; i < leftUp5.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','5','" + leftUp5[i] + "','" + rightUp5[i] + "','" + leftDown5[i] + "','" + rightDown5[i] + "','" + remarks5[i] + "')";
            sqlMapper.insert(sql2);
        }
        String sql1 = "update " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " set is_status =1 where id='" + info.getCustomerId() + "'";
        sqlMapper.update(sql1);
        String getcust = "select * from " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " where id='" + info.getCustomerId() + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(getcust, CustomerInfo.class);
        //插入新增日志
        String inertsq1 = "INSERT INTO `case_info_log` (createtime,reservations_id,case_id,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + customerInfo.getReservationsId() + "','" + case_id + "','" + ShiroKit.getUser().getAccount() + "','新增病历','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','" + ShiroKit.getUser().getAccount() + " 把 " + customerInfo.getCustomerName() + " 的病历在:" + DateTimeKit.now() + "进行添加','" + customerInfo.getId() + "');";
        sqlMapper.insert(inertsq1);
        return "1"+","+id;
    }

    @Override
    public String insert1(CaseInfo info) {
        String id = CommUtils.getUUID();
        Random rand = new Random();
        int randomNumber = rand.nextInt(999999);
        id = id + randomNumber;
        String finnallyTime = "";
        if (info.getFinnallyTime() == null || info.getFinnallyTime() == "") {
            finnallyTime = "null";
        } else {
            finnallyTime = "'" + info.getFinnallyTime() + "'";
        }
        String sql11="select * from dept where simplename='"+ ShiroKit.getUser().getOutpatientName()+"'";
        Dept dept=sqlMapper.selectOne(sql11,Dept.class);
        String sql22="select * from "+dept.getAreaAbbreviation()+"pay_service_info where id='"+info.getPayServiceId()+"'";
        PayServiceInfo py=sqlMapper.selectOne(sql22,PayServiceInfo.class);
        String sql = "insert into case_info (`id`,`customer_id`,`reservations_id`,`zhushu`,`doctor_id`,`nurse_id`,`type`,`now_medical_history`,`before_medical_history`,`finnally_time`,`doctor_advice`,`lable`,remarkss" +
                ",mouth_check ,auxiliary_check ,diagnose ,remedy_plan ,dispose ,pay_service_id,status,arrival_store,abbreviation,founder,update_time) VALUES" +
                "('" + id + "','" + info.getCustomerId() + "','" + info.getReservationsId() + "','" + info.getZhushu() + "','" + info.getDoctorId() + "','" + info.getNurseId() + "','" + info.getType() + "','" + info.getNowMedicalHistory() + "','" + info.getBeforeMedicalHistory() + "'" +
                "," + finnallyTime + ",'" + info.getDoctorAdvice() + "' ,'" + info.getLable() + "','" + info.getRemarks() + "','1','2','3','4','5'" +
                ",'" + info.getPayServiceId() + "'," + info.getStatus() + ",'" + ShiroKit.getUser().getOutpatientName()
                + "','" + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"" + "','" + ShiroKit.getUser().getAccount()
                + "','" + DateTimeKit.now() + "');";
        sqlMapper.insert(sql);
        String case_id = id;
        //第一组检查循环插入
        String[] leftUp1 = info.getLeftUp1().split("&&", -1);//
        String[] rightUp1 = info.getRightUp1().split("&&", -1);
        String[] leftDown1 = info.getLeftDown1().split("&&", -1);
        String[] rightDown1 = info.getRightDown1().split("&&", -1);
        String[] remarks1 = info.getRemarks1().split("&&", -1);
        for (int i = 0; i < leftUp1.length; i++) {
            String sql1 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','1','" + leftUp1[i] + "','" + rightUp1[i] + "','" + leftDown1[i] + "','" + rightDown1[i] + "','" + remarks1[i] + "')";
            sqlMapper.insert(sql1);
        }
        //第二组检查循环插入
        String[] leftUp2 = info.getLeftUp2().split("&&", -1);
        String[] rightUp2 = info.getRightUp2().split("&&", -1);
        String[] leftDown2 = info.getLeftDown2().split("&&", -1);
        String[] rightDown2 = info.getRightDown2().split("&&", -1);
        String[] remarks2 = info.getRemarks2().split("&&", -1);
        for (int i = 0; i < leftUp2.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','2','" + leftUp2[i] + "','" + rightUp2[i] + "','" + leftDown2[i] + "','" + rightDown2[i] + "','" + remarks2[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第三组检查循环插入
        String[] leftUp3 = info.getLeftUp3().split("&&", -1);
        String[] rightUp3 = info.getRightUp3().split("&&", -1);
        String[] leftDown3 = info.getLeftDown3().split("&&", -1);
        String[] rightDown3 = info.getRightDown3().split("&&", -1);
        String[] remarks3 = info.getRemarks3().split("&&", -1);
        for (int i = 0; i < leftUp3.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','3','" + leftUp3[i] + "','" + rightUp3[i] + "','" + leftDown3[i] + "','" + rightDown3[i] + "','" + remarks3[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第四组检查循环插入
        String[] leftUp4 = info.getLeftUp4().split("&&", -1);
        String[] rightUp4 = info.getRightUp4().split("&&", -1);
        String[] leftDown4 = info.getLeftDown4().split("&&", -1);
        String[] rightDown4 = info.getRightDown4().split("&&", -1);
        String[] remarks4 = info.getRemarks4().split("&&", -1);
        for (int i = 0; i < leftUp4.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','4','" + leftUp4[i] + "','" + rightUp4[i] + "','" + leftDown4[i] + "','" + rightDown4[i] + "','" + remarks4[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第五组检查循环插入
        String[] leftUp5 = info.getLeftUp5().split("&&", -1);
        String[] rightUp5 = info.getRightUp5().split("&&", -1);
        String[] leftDown5 = info.getLeftDown5().split("&&", -1);
        String[] rightDown5 = info.getRightDown5().split("&&", -1);
        String[] remarks5 = info.getRemarks5().split("&&", -1);
        for (int i = 0; i < leftUp5.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','5','" + leftUp5[i] + "','" + rightUp5[i] + "','" + leftDown5[i] + "','" + rightDown5[i] + "','" + remarks5[i] + "')";
            sqlMapper.insert(sql2);
        }
        String sql1 = "update " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " set is_status =1 where id='" + info.getCustomerId() + "'";
        String sql2 = "update " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " set arrival_status =4 where id='" + info.getCustomerId() + "'";
        sqlMapper.update(sql1);
        String getcust = "select * from " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " where id='" + info.getCustomerId() + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(getcust, CustomerInfo.class);
        //插入新增日志
        String inertsq1 = "INSERT INTO `case_info_log` (createtime,reservations_id,case_id,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + customerInfo.getReservationsId() + "','" + case_id + "','" + ShiroKit.getUser().getAccount() + "','新增病历','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','" + ShiroKit.getUser().getAccount() + " 把 " + customerInfo.getCustomerName() + " 的病历在:" + DateTimeKit.now() + "进行添加','" + customerInfo.getId() + "');";
        sqlMapper.insert(inertsq1);
        sqlMapper.update(sql2);
        return "1,"+id;
    }

    public int delete(CaseInfo info) {
        return 0;
    }

    public int update(CaseInfo info) {
        String selectSql2 = "select * from " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " t where id='" + info.getCustomerId() + "'";
        CustomerInfo customerInfo = sqlMapper.selectOne(selectSql2, CustomerInfo.class);
        //根据传入的病例ID，删除掉病例原有关联的牙位信息
        String sql = "delete from tooth_site where case_id ='" + info.getId() + "'";
        sqlMapper.delete(sql);
        //重新插入牙位表信息
        String case_id = info.getId();
        //第一组检查循环插入
        String[] leftUp1 = info.getLeftUp1().split("&&", -1);
        String[] rightUp1 = info.getRightUp1().split("&&", -1);
        String[] leftDown1 = info.getLeftDown1().split("&&", -1);
        String[] rightDown1 = info.getRightDown1().split("&&", -1);
        String[] remarks1 = info.getRemarks1().split("&&", -1);
        for (int i = 0; i < leftUp1.length; i++) {
            String sql1 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','1','" + leftUp1[i] + "','" + rightUp1[i] + "','" + leftDown1[i] + "','" + rightDown1[i] + "','" + remarks1[i] + "')";
            sqlMapper.insert(sql1);
        }
        //第二组检查循环插入
        String[] leftUp2 = info.getLeftUp2().split("&&", -1);
        String[] rightUp2 = info.getRightUp2().split("&&", -1);
        String[] leftDown2 = info.getLeftDown2().split("&&", -1);
        String[] rightDown2 = info.getRightDown2().split("&&", -1);
        String[] remarks2 = info.getRemarks2().split("&&", -1);
        for (int i = 0; i < leftUp2.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','2','" + leftUp2[i] + "','" + rightUp2[i] + "','" + leftDown2[i] + "','" + rightDown2[i] + "','" + remarks2[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第三组检查循环插入
        String[] leftUp3 = info.getLeftUp3().split("&&", -1);
        String[] rightUp3 = info.getRightUp3().split("&&", -1);
        String[] leftDown3 = info.getLeftDown3().split("&&", -1);
        String[] rightDown3 = info.getRightDown3().split("&&", -1);
        String[] remarks3 = info.getRemarks3().split("&&", -1);
        for (int i = 0; i < leftUp3.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','3','" + leftUp3[i] + "','" + rightUp3[i] + "','" + leftDown3[i] + "','" + rightDown3[i] + "','" + remarks3[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第四组检查循环插入
        String[] leftUp4 = info.getLeftUp4().split("&&", -1);
        String[] rightUp4 = info.getRightUp4().split("&&", -1);
        String[] leftDown4 = info.getLeftDown4().split("&&", -1);
        String[] rightDown4 = info.getRightDown4().split("&&", -1);
        String[] remarks4 = info.getRemarks4().split("&&", -1);
        for (int i = 0; i < leftUp4.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','4','" + leftUp4[i] + "','" + rightUp4[i] + "','" + leftDown4[i] + "','" + rightDown4[i] + "','" + remarks4[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第五组检查循环插入
        String[] leftUp5 = info.getLeftUp5().split("&&", -1);
        String[] rightUp5 = info.getRightUp5().split("&&", -1);
        String[] leftDown5 = info.getLeftDown5().split("&&", -1);
        String[] rightDown5 = info.getRightDown5().split("&&", -1);
        String[] remarks5 = info.getRemarks5().split("&&", -1);
        for (int i = 0; i < leftUp5.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','5','" + leftUp5[i] + "','" + rightUp5[i] + "','" + leftDown5[i] + "','" + rightDown5[i] + "','" + remarks5[i] + "')";
            sqlMapper.insert(sql2);
        }
        //根据病例ID修改对应的病例信息
        String sql6 = "update case_info a set a.case_status=0, a.zhushu='" + info.getZhushu().trim() + "',a.now_medical_history='" + info.getNowMedicalHistory().trim() + "'," +
                "a.doctor_id='" + info.getDoctorId().trim() + "',a.nurse_id='" + info.getNurseId().trim() + "'," +
                "a.before_medical_history='" + info.getBeforeMedicalHistory().trim() + "'," +
                "a.doctor_advice='" + info.getDoctorAdvice().trim() + "',a.type='" + info.getType() + "'," +
                "a.remarkss='" + info.getRemarks() + "',a.finnally_time='" + info.getFinnallyTime() + "' ," +
                "a.pay_service_id='" + info.getPayServiceId() + "',a.status=" + info.getStatus() +
                " where id = '" + info.getId() + "'";
        //编辑病历 插入日志
        String inertsq1 = "INSERT INTO `case_info_log` (createtime,reservations_id,case_id,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + customerInfo.getReservationsId() + "','" + case_id + "','" + ShiroKit.getUser().getAccount() + "','编辑病历','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','" + ShiroKit.getUser().getAccount() + " 把 " + customerInfo.getCustomerName() + " 的病历在:" + DateTimeKit.now() + "进行修改','" + info.getCustomerId() + "');";
        sqlMapper.insert(inertsq1);
        return sqlMapper.update(sql6);
    }

    @Override
    public int updateFinsh(CaseInfo info) {
        //根据传入的病例ID，删除掉病例原有关联的牙位信息
        String sql = "delete from tooth_site where case_id ='" + info.getId() + "'";
        sqlMapper.delete(sql);
        //重新插入牙位表信息
        String case_id = info.getId();
        //第一组检查循环插入
        String[] leftUp1 = info.getLeftUp1().split("&&", -1);
        String[] rightUp1 = info.getRightUp1().split("&&", -1);
        String[] leftDown1 = info.getLeftDown1().split("&&", -1);
        String[] rightDown1 = info.getRightDown1().split("&&", -1);
        String[] remarks1 = info.getRemarks1().split("&&", -1);
        for (int i = 0; i < leftUp1.length; i++) {
            String sql1 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','1','" + leftUp1[i] + "','" + rightUp1[i] + "','" + leftDown1[i] + "','" + rightDown1[i] + "','" + remarks1[i] + "')";
            sqlMapper.insert(sql1);
        }
        //第二组检查循环插入
        String[] leftUp2 = info.getLeftUp2().split("&&", -1);
        String[] rightUp2 = info.getRightUp2().split("&&", -1);
        String[] leftDown2 = info.getLeftDown2().split("&&", -1);
        String[] rightDown2 = info.getRightDown2().split("&&", -1);
        String[] remarks2 = info.getRemarks2().split("&&", -1);
        for (int i = 0; i < leftUp2.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','2','" + leftUp2[i] + "','" + rightUp2[i] + "','" + leftDown2[i] + "','" + rightDown2[i] + "','" + remarks2[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第三组检查循环插入
        String[] leftUp3 = info.getLeftUp3().split("&&", -1);
        String[] rightUp3 = info.getRightUp3().split("&&", -1);
        String[] leftDown3 = info.getLeftDown3().split("&&", -1);
        String[] rightDown3 = info.getRightDown3().split("&&", -1);
        String[] remarks3 = info.getRemarks3().split("&&", -1);
        for (int i = 0; i < leftUp3.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','3','" + leftUp3[i] + "','" + rightUp3[i] + "','" + leftDown3[i] + "','" + rightDown3[i] + "','" + remarks3[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第四组检查循环插入
        String[] leftUp4 = info.getLeftUp4().split("&&", -1);
        String[] rightUp4 = info.getRightUp4().split("&&", -1);
        String[] leftDown4 = info.getLeftDown4().split("&&", -1);
        String[] rightDown4 = info.getRightDown4().split("&&", -1);
        String[] remarks4 = info.getRemarks4().split("&&", -1);
        for (int i = 0; i < leftUp4.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','4','" + leftUp4[i] + "','" + rightUp4[i] + "','" + leftDown4[i] + "','" + rightDown4[i] + "','" + remarks4[i] + "')";
            sqlMapper.insert(sql2);
        }
        //第五组检查循环插入
        String[] leftUp5 = info.getLeftUp5().split("&&", -1);
        String[] rightUp5 = info.getRightUp5().split("&&", -1);
        String[] leftDown5 = info.getLeftDown5().split("&&", -1);
        String[] rightDown5 = info.getRightDown5().split("&&", -1);
        String[] remarks5 = info.getRemarks5().split("&&", -1);
        for (int i = 0; i < leftUp5.length; i++) {
            String sql2 = "insert into tooth_site (case_id,ya_type,left_up,right_up,left_down,right_down,remarks) VALUES" +
                    "('" + case_id + "','5','" + leftUp5[i] + "','" + rightUp5[i] + "','" + leftDown5[i] + "','" + rightDown5[i] + "','" + remarks5[i] + "')";
            sqlMapper.insert(sql2);
        }
        //根据病例ID修改对应的病例信息
        String sql6 = "update case_info a set a.zhushu='" + info.getZhushu().trim() + "',a.now_medical_history='" + info.getNowMedicalHistory().trim() + "'," +
                "a.doctor_id='" + info.getDoctorId().trim() + "',a.nurse_id='" + info.getNurseId().trim() + "'," +
                "a.before_medical_history='" + info.getBeforeMedicalHistory().trim() + "'," +
                "a.doctor_advice='" + info.getDoctorAdvice().trim() + "',a.type='" + info.getType() + "'," +
                "a.remarkss='" + info.getRemarks() + "',a.finnally_time='" + info.getFinnallyTime() + "' ," +
                "a.pay_service_id='" + info.getPayServiceId() + "',a.status=" + info.getStatus() +
                " where id = '" + info.getId() + "'";
        String sql2 = "update " + redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0) + " set arrival_status =4 where id='" + info.getCustomerId() + "'";
        sqlMapper.update(sql2);
        return sqlMapper.update(sql6);
    }

    //上传正畸
    public String upLoadOrthodontics(MultipartFile picture, String cri) {
        String num = cri.split(",")[0];
        String imgtpye = cri.split(",")[1];
        String classification = cri.split(",")[2];
        String reservationsId = cri.split(",")[3];
        String realPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang\\orthodontics";
        //String httpUrl = "http://118.123.15.60:8068/yingxiang/orthodontics/";
        //避免出现相同的图片名称  ids
        String randomNumbersql = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumbersql, DaulInfo.class);
        String imageurl = "yingxiang/orthodontics/" + infos.getRandomNumber()+num.substring(num.length()-6)+".png";
        try {
//            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath, infos.getRandomNumber() +".png"));
            aliyunOssUtil.pushSingleFile(picture, imageurl);
            String sql = "INSERT INTO `root_orthodontics_imgs_info` (`image_url`, `num`, `imgtpye`, `classification`,reservations_id,create_name) VALUES " +
                    "( '" + MemberEnumConfig.ossphoeurl+imageurl + "', '" + num + "', '" + imgtpye + "', '" + classification + "','" + reservationsId + "','"+ShiroKit.getUser().getAccount()+"');";
            sqlMapper.insert(sql);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return MemberEnumConfig.ossphoeurl+imageurl;
    }

    //上传根管
    public String upLoadRootCanal(MultipartFile picture, String cri) {
        String num = cri.split(",")[0];
        String reservationsId = cri.split(",")[1];
        String realPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang\\rootCanal";
        String httpUrl = "http://118.123.15.60:8068/yingxiang/rootCanal/";
        //避免出现相同的图片名称  ids
        String randomNumbersql = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumbersql, DaulInfo.class);
        String imageurl = "yingxiang/rootCanal/" + infos.getRandomNumber()+".png";
        try {
            aliyunOssUtil.pushSingleFile(picture, imageurl);
            //FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath,infos.getRandomNumber() +".png"));
            String sql = "insert into root_canal_imgs_info (num, image_url,reservations_id,create_name) VALUES " +
                    "('" + num + "','" +MemberEnumConfig.ossphoeurl+imageurl + "','" + reservationsId + "','"+ShiroKit.getUser().getAccount()+"');";
            sqlMapper.insert(sql); //上传主图
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return MemberEnumConfig.ossphoeurl+imageurl;
    }

    //上传洁牙
    public String uploadScaling(MultipartFile picture, String cri) {
        String num = cri.split(",")[0];
        String imgtpye = cri.split(",")[1];
        String classification = cri.split(",")[2];
        String reservationsId = cri.split(",")[3];
        String realPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang\\scaling";
        String httpUrl = "http://118.123.15.60:8068/yingxiang/scaling/";
        //避免出现相同的图片名称  ids
        String randomNumbersql = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumbersql, DaulInfo.class);
        String imageurl = "yingxiang/scaling/" + infos.getRandomNumber()+".png";
        try {
//            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath, infos.getRandomNumber() +".png"));
            aliyunOssUtil.pushSingleFile(picture, imageurl);
            String sql = "INSERT INTO `root_scaling_imgs_info` (`image_url`, `num`, `imgtpye`, `classification`,reservations_id,create_name) VALUES " +
                    "( '"+MemberEnumConfig.ossphoeurl+imageurl + "', '" + num + "', '" + imgtpye + "', '" + classification + "','" + reservationsId + "','"+ShiroKit.getUser().getAccount()+"');";
            sqlMapper.insert(sql);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return MemberEnumConfig.ossphoeurl+imageurl;
    }

    //上传牙周
    public String uploadPeriodontal(MultipartFile picture, String cri) {
        String num = cri.split(",")[0];
        String imgtpye = cri.split(",")[1];
        String classification = cri.split(",")[2];
        String reservationsId = cri.split(",")[3];
        String realPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang\\periodontal";
        String httpUrl = "http://118.123.15.60:8068/yingxiang/periodontal/";
        //避免出现相同的图片名称  ids
        String randomNumbersql = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumbersql, DaulInfo.class);
        String imageurl ="yingxiang/periodontal/" + infos.getRandomNumber()+".png";
        try {
//            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath,infos.getRandomNumber() +".png"));
            aliyunOssUtil.pushSingleFile(picture, imageurl);
            String sql = "INSERT INTO `root_periodontal_imgs_info` (`image_url`, `num`, `imgtpye`, `classification`,reservations_id,create_name) VALUES " +
                    "( '"+MemberEnumConfig.ossphoeurl+ imageurl + "', '" + num + "', '" + imgtpye + "', '" + classification + "','" + reservationsId + "','"+ShiroKit.getUser().getAccount()+"');";
            sqlMapper.insert(sql);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return MemberEnumConfig.ossphoeurl+imageurl;
    }

    //上传种植
    public String uploadPlantScoreFirst(MultipartFile picture, String cri) {
        String num = cri.split(",")[0];
        String imgtpye = cri.split(",")[1];
        String classification = cri.split(",")[2];
        String reservationsId = cri.split(",")[3];
        String realPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang\\periodontal";
        String httpUrl = "http://118.123.15.60:8068/yingxiang/periodontal/";
        //避免出现相同的图片名称  ids
        String randomNumbersql = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumbersql, DaulInfo.class);
        String imageurl = "yingxiang/periodontal/" + infos.getRandomNumber()+".png";
        try {
//            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath, infos.getRandomNumber() +".png"));
            aliyunOssUtil.pushSingleFile(picture, imageurl);
            String sql = "INSERT INTO `root_plant_imgs_info` (`image_url`, `num`, `imgtpye`, `classification`,reservations_id,create_name) VALUES " +
                    "( '" +MemberEnumConfig.ossphoeurl+ imageurl + "', '" + num + "', '" + imgtpye + "', '" + classification + "','" + reservationsId + "','"+ShiroKit.getUser().getAccount()+"');";
            sqlMapper.insert(sql);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return MemberEnumConfig.ossphoeurl+imageurl;
    }

    //上传修复
    public String uploadRepair(MultipartFile picture, String cri) {
        String num = cri.split(",")[0];
        String imgtpye = cri.split(",")[1];
        String classification = cri.split(",")[2];
        String reservationsId = cri.split(",")[3];
        String realPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang\\periodontal";
        String httpUrl = "http://118.123.15.60:8068/yingxiang/periodontal/";
        //避免出现相同的图片名称  ids
        String randomNumbersql = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumbersql, DaulInfo.class);
        String imageurl ="yingxiang/periodontal/" + infos.getRandomNumber()+".png";
        try {
//            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath, infos.getRandomNumber() +".png"));
            aliyunOssUtil.pushSingleFile(picture, imageurl);
            String sql = "INSERT INTO `root_repair_imgs_info` (`image_url`, `num`, `imgtpye`, `classification`,reservations_id,create_name) VALUES " +
                    "( '"+MemberEnumConfig.ossphoeurl+ imageurl + "', '" + num + "', '" + imgtpye + "', '" + classification + "','" + reservationsId + "','"+ShiroKit.getUser().getAccount()+"');";
            sqlMapper.insert(sql);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return MemberEnumConfig.ossphoeurl+imageurl;
    }

    @Override
    public List<DoctorChangePriceInfo> selectDoctorPerformanceGetMap(Page<DoctorChangePriceInfo> page, SearchDoctorChangePriceInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getTreatmentUnit())) {
            params.put("treatmentUnit", searchInfo.getTreatmentUnit());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFieldTc())) {
            params.put("fieldTc", searchInfo.getFieldTc());
        }
        if (StringUtil.isNotEmpty(searchInfo.getAppointmentPayService())) {
            params.put("appointmentPayService", searchInfo.getAppointmentPayService());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        } else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableName1 = tableHead + "triage_performance";
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("tableName1", tableName1);
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPerformance(page, params);
    }

    @Override
    public List<DoctorChangePriceInfo> selectDoctorPerformanceGetFen(Page<DoctorChangePriceInfo> page, SearchDoctorChangePriceInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getTreatmentUnit())) {
            params.put("treatmentUnit", searchInfo.getTreatmentUnit());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFieldTc())) {
            params.put("fieldTc", searchInfo.getFieldTc());
        }
        if (StringUtil.isNotEmpty(searchInfo.getAppointmentPayService())) {
            params.put("appointmentPayService", searchInfo.getAppointmentPayService());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        } else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        String tableHead = redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Abbreviation",0)+"";
        String tableName1 = tableHead + "triage_performance";
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("tableName1", tableName1);
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPerformanceFen(page, params);
    }
}
